package com.ymatou.sellerproduct.api.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.sellerproduct.api.parameter.AddSellerProductBean;
import com.ymatou.sellerproduct.api.parameter.CatalogNewData;
import com.ymatou.sellerproduct.api.parameter.ProductAndCatalogNewData;
import com.ymatou.sellerproduct.api.service.AddSellerProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.ECode;

/**
 * 添加商品接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddSellerProduct {
	private static AddSellerProductBean addproductbean;
	private static AddSellerProductCall addproductcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加商品接口");
	}

	@Before
	public void caseUp() {
		addproductbean = new AddSellerProductBean();
		addproductcall = new AddSellerProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addproductcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_AddSellerProduct_001() {
		Logger.start(true,"添加商品成功");
		try {
			String rid=TestDataManager.getRandomUUID().toString().replaceAll("-", "");
			ProductAndCatalogNewData product=new ProductAndCatalogNewData();
			product.setiCategoryId(1002);
			product.setiThirdCategoryId(1003);
			product.setIsSailProtected(false);
			product.setProductName("接口自动化测试Test"+rid);
			product.setPictureUrl1("http://p243.img.ymatou.com:10243/upload/productdes/3afa103d4ec4466f824b9f0458d6f4e2.jpg");
			product.setPictureUrl2("http://p243.img.ymatou.com:10243/upload/productdes/7749d985e60e45a7a7c556873775f998.jpg");
			product.setPictureUrl3("http://172.16.100.64/group1/M00/00/BC/rBBkQFWadMOAALiKAAFuo51Y5lA987.jpg");
			product.setDescription("接口自动化测试Test description:"+rid);
			//品牌ID   select top  10 *from Ymt_ProductBrand
			product.setiBrandId(10145);
			product.setAcceptReturn(0);
			 //配送方式 1国内快递、2直邮、3贝海直邮、4卖家保税、5FBX贝海保税、6认证直邮、7拼邮
			product.setCatalogStatus(2);
			//库存位置  0海外，1保税，2国内
			product.setInventoryLocation(2);
			//新的配送方式
			product.setLogisticsChannel(6);
			 //商品类型，0现货、1代购、2FBX
			product.setCatalogType(1);
			product.setWeight(new BigDecimal(0));
			product.setLimited(true);
			product.setLimitNum(2000);
			Date now=YMTDateUtil.getDate();
			String fnow=YMTDateUtil.getFormatTime(now, "yyyy/MM/dd HH:mm:ss");
			String fnow2=YMTDateUtil.getFormatTime(now, "MM/dd/yyyy HH:mm:ss");
			String ffuture=YMTDateUtil.getBeforeOrNextDay(365,"MM/dd/yyyy HH:mm:ss");
			product.setLimitNumStartTime(fnow);
			product.setAvailable(true);
//			product.setProductProperty("NewPropertyName_1=商品属性Key&NewProperty_1=商品属性Value&");
			product.setAvailableNow(true);
			product.setValidStart(fnow2);
			product.setValidEnd(ffuture);
			product.setAutoRefresh(false);
			product.setFreightForBuyerType(-1);
			product.setUseDuplicateSKU(false);
			List<CatalogNewData> catalogs=new ArrayList<CatalogNewData>();
			CatalogNewData catalog=new CatalogNewData();
			catalog.setPrice(new BigDecimal(100));
			catalog.setNum(2000);
			catalog.setSKU("YMT"+rid);
			catalogs.add(catalog);
			product.setCatalogs(catalogs);
			addproductbean.setProduct(product);
			addproductbean.setUserID(288484);
			addproductcall.setData(addproductbean);
			addproductcall.callService();
			Logger.comment("添加商品 send:" + addproductcall.getEntityString());
			Logger.comment("添加商品 response:" + addproductcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, addproductcall.getCode(), "验证Code");
			Logger.verifyNotNull(addproductcall.getProductID(), "验证ProductID");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}